﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for clsUsersList
/// </summary>
public class clsUsersList
{

    #region MEMBER VARIABLES

    protected DataSet m_dtsUsers;
    protected DataView m_dtvUsers;

    public System.Collections.ObjectModel.Collection<clsUsersRecord> colReturn;
    clsUser m_clsUser;

    #endregion

    #region PROPERTIES

    public String FilterExpression
    {
        get
        {
            return m_dtvUsers.RowFilter;
        }
        set
        {
            m_dtvUsers.RowFilter = value;
        }
    }

    public String SortExpression
    {
        get
        {
            return m_dtvUsers.Sort;
        }
        set
        {
            m_dtvUsers.Sort = value;
        }
    }

    #endregion

    #region CONSTRUCTORS

    public clsUsersList(clsUser clsUser)
    {
        m_clsUser = clsUser;
        Initialise();
    }

    #endregion

    #region PUBLIC METHODS

    public DataView GetRecords()
    {
        return m_dtvUsers;
    }

    public System.Collections.ObjectModel.Collection<clsUsersRecord> GetItemCollection()
    {
        colReturn = new System.Collections.ObjectModel.Collection<clsUsersRecord>();
        DataTable tblUsers = this.GetRecords().ToTable();
        for (int iCount = 0; iCount < tblUsers.Rows.Count; iCount++)
        {
            colReturn.Add(new clsUsersRecord(this.m_clsUser, int.Parse(tblUsers.Rows[iCount]["iUserID"].ToString())));
        }
        return colReturn;
    }

    #endregion

    #region PROTECTED METHODS

    protected void Initialise()
    {

        try
        {
            m_dtsUsers = DataConnection.GetDataObject().GetData("Data", "spUsersList");
            m_dtvUsers = m_dtsUsers.Tables[0].DefaultView;
        }
        catch (Exception ex)
        {
            clsErrorLog.LogError(ex, this, m_clsUser, 95);
            throw ex;
        }

    }

    #endregion

}
